import React, { Component } from "react";

export default class Header extends Component {
  handleKeyUp = (event) => {
    if (event.keyCode === 13) {
      if(event.target.value.trim() === ''){
        alert('不能为空')
        return
      }
      const todo = {
        id: "00" + (this.props.length+1),
        name: event.target.value,
        done: "false",
      };
      this.props.getData(todo);
      event.target.value = ''
    }
  };
  render() {
    return (
      <div className="todo-header">
        <input
          type="text"
          onKeyUp={this.handleKeyUp}
          placeholder="请输入你的任务名称，按回车键确认"
        />
      </div>
    );
  }
}
